import { Entity, Column, PrimaryGeneratedColumn, ManyToOne, JoinColumn } from 'typeorm'
import { OrderEntity } from './order.entity'

@Entity('order_item')
export class OrderItemEntity {
  @PrimaryGeneratedColumn()
  id: number

  // 关联订单主表
  @ManyToOne(() => OrderEntity, (order) => order.items, { onDelete: 'CASCADE' })
  @JoinColumn({ name: 'order_id' }) // 指定外键字段名
  order: OrderEntity

  @Column({ type: 'int', comment: '菜品ID' })
  menu_id: number

  @Column({ type: 'varchar', length: 100, comment: '菜品名称' })
  menu_name: string

  @Column({ type: 'decimal', precision: 10, scale: 2, comment: '菜品单价' })
  menu_fee: number

  @Column({ type: 'int', comment: '份数' })
  quantity: number

  @Column()
  menu_photo: string
}